<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <img id="pic" src="images/1.jpg" style="width:200px"/>
    <input type="button" value="上一张" onclick="previous()"/>
    <input type="button" value="下一张" onclick="next()"/>

    <script type="text/javascript">
        var a = 1;
       function next(){
           if(a<5){
               a = a+1;
               pic.src = "images/"+a+".jpg";


           }else{
               alert("已经是最后一张照片");
           }
       }
       function previous(){
           if(a<2){
               alert("已经是第一张照片")

           }else{
               a = a-1;
               pic.src = "images/"+a+".jpg";


           }
       }
    </script>


    </body>
</html>